package stu.aistar.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import stu.aistar.mapper.UserMapper;
import stu.aistar.model.pojo.User;
import stu.aistar.service.UserService;
import stu.aistar.util.CodeUtils;

import java.util.Map;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private  UserMapper userMapper;

    @Override
    public User findUserByPhone(String phone) {
        return userMapper.findUserByPhone(phone);
    }

    @Override
    public User login(String phone, String password) {
        return userMapper.findUserByPhoneAndPassword(phone,password);
    }

    @Override
    public User registUser(String phone, String password) {
        User user = new User();
        user.setPhone(phone);
        user.setPassword(password);
        user.setPower(0);
        return userMapper.save(user);
    }

    @Override
    public String sendVerifyCode(String phoneNumber, Integer code_length, Map<String, String> map) {
        return CodeUtils.sendVerifyCode(phoneNumber, code_length, map);
    }
}
